#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, k, f[301][301];
int main() {
	scanf("%lld%lld%lld", &n, &m, &k);
	memset(f, 127, sizeof(f));
	for (ll i = 1; i <= n; ++i)
		f[i][i] = 0;
	for (ll i = 1; i <= m; ++i) {
		ll x, y, z;
		scanf("%lld%lld%lld", &x, &y, &z);
		f[x][y] = z;
	}
	for (ll k = 1; k <= n; ++k)
		for (ll i = 1; i <= n; ++i)
			for (ll j = 1; j <= n; ++j)
				if (f[i][k] < 1 << 30 && f[k][j] < 1 << 30)
					f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	for (; k--; ) {
		ll s, t;
		scanf("%lld%lld", &s, &t);
		if (f[s][t] < 1 << 30)
			printf("%lld\n", f[s][t]);
		else
			printf("-1\n");
	}
	return 0;
}
